Bug 541645 – gtkfilechooserdefault segfaults when bookmark does not
authorMatthias Clasen <mclasen@redhat.com>
Sun, 6 Jul 2008 05:34:03 +0000 (05:34 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Sun, 6 Jul 2008 05:34:03 +0000 (05:34 +0000)
2008-07-06  Matthias Clasen  <mclasen@redhat.com>

        Bug 541645 – gtkfilechooserdefault segfaults when bookmark does not
        contain ://

        * gtk/gtkfilechooserdefault.c (_gtk_file_chooser_label_for_file):
        Be more robust. Reported by  Jelte van der Hoek

svn path=/trunk/; revision=20787

ChangeLog
gtk/gtkfilechooserdefault.c

index 943ccc1c1126278e2f5343caa328603e29a4c235..66b64b28fd5c18ad21a81160fdd6a4b09a3f5313 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2008-07-06  Matthias Clasen  <mclasen@redhat.com>
+
+       Bug 541645 – gtkfilechooserdefault segfaults when bookmark does not
+       contain ://
+
+       * gtk/gtkfilechooserdefault.c (_gtk_file_chooser_label_for_file):
+       Be more robust. Reported by  Jelte van der Hoek
+
 2008-07-06  Matthias Clasen  <mclasen@redhat.com>
 
        Bug 540917 – deprecate pack_start_defaults()
index 458bdee71ac1a4244643f7c0030d09f756114ca6..c101492ed43e6a7a0a7294728af491b362b483e4 100644 (file)
@@ -1621,37 +1621,42 @@ _gtk_file_chooser_label_for_file (GFile *file)
   uri = g_file_get_uri (file);
 
   start = strstr (uri, "://");
-  start += 3;
-  path = strchr (start, '/');
-  
-  if (path)
-    end = path;
-  else
+  if (start)
     {
-      end = uri + strlen (uri);
-      path = "/";
-    }
+      start += 3;
+      path = strchr (start, '/');
+      if (path)
+        end = path;
+      else
+        {
+          end = uri + strlen (uri);
+          path = "/";
+        }
 
-  /* strip username */
-  p = strchr (start, '@');
-  if (p && p < end)
-    {
-      start = p + 1;
-    }
+      /* strip username */
+      p = strchr (start, '@');
+      if (p && p < end)
+        start = p + 1;
   
-  p = strchr (start, ':');
-  if (p && p < end)
-    end = p;
+      p = strchr (start, ':');
+      if (p && p < end)
+        end = p;
   
-  host = g_strndup (start, end - start);
-
-  /* Translators: the first string is a path and the second string 
-   * is a hostname. Nautilus and the panel contain the same string 
-   * to translate. 
-   */
-  label = g_strdup_printf (_("%1$s on %2$s"), path, host);
+      host = g_strndup (start, end - start);
+  
+      /* Translators: the first string is a path and the second string 
+       * is a hostname. Nautilus and the panel contain the same string 
+       * to translate. 
+       */
+      label = g_strdup_printf (_("%1$s on %2$s"), path, host);
+  
+      g_free (host);
+    }
+  else
+    {
+      label = g_strdup (uri);
+    }
   
-  g_free (host);
   g_free (uri);
 
   return label;